<?php
/**
 * Yotaku Shop - yshop
 * @author Creatint<creatint@163.com>
 * @copyright www.yotaku.cn 2016
 */
namespace Admin\Controller;
use Think\Page;
class UserController extends AdminController {
    public function index($p=1){

        //用户数据
        $params = I('get.');
        $User   =   D("User");
        $users   =   $User->getUsers($params,$page=false);
        trace($users,'users');
        $this->assign('users',$users);
        $show     =   $User->getShow();

        $this->assign('users',$users);
        $this->assign('show',$show);
        $this->display();

    }

    public function add(){
        $this->display();
    }
    public function edit($id){
        //获取用户数据
        $User   =   D("User");
        $info   =   $User->getDetail($id);
        trace($info,'info');
        if(!$info){
            $this->error($User->getError());
        }
        $this->assign('info',$info);
        $this->display();
    }

    public function delete($id){
        $User   =   D("User");
        $id = array_unique((array)I('id',0));
        $res = $User->del($id);
        if($res){
            $this->success('删除成功');
        }else{
            $this->error('删除失败 '.$User->getError());
        }
    }

    public function update(){
        if(IS_POST){
            $User = D("User");
            $data = $_POST;
            $data = array_filter($data);
            trace($_POST,'post');
            $status = true;
            if($res = $User->update($data)){
                $this->success($res['id']?'修改成功':'新增成功');
            }else{
                $this->error($User->getError());
            }

        }
    }
}